﻿var Express = require('express');
var multer = require('multer');
var bodyParser = require('body-parser');
var app = Express();
app.use(bodyParser.json());
var Storage = multer.diskStorage({
    destination: function (req, file, callback) {
        callback(null, "./Images");
    },
    filename: function (req, file, callback) {
    	 var fileFormat = (file.originalname).split(".");
    	 console.log(fileFormat[1])
        callback(null, "imges" + "_" + Date.now() + "." + fileFormat[1]);
        console.log(file.fieldname+"------->>>>>>"+file.originalname);
    }
});
var upload = multer({ storage: Storage }).array("imgUploader", 3); //字段名和最大计数

app.get("/", function (req, res) {
    res.sendFile(__dirname + "/index.html");
});
app.post("/api/Upload", function (req, res){
    upload(req, res, function (err) {
        if (err) {
            return res.json({"code":1001,"text":"no!"});
        }
          return res.json({"code":1000,"text":"ok"});
    });
});

app.listen(2000, function (a) {
    console.log("Listening to port 2000");
});
